﻿#region 程序集 VanillaPsycastsExpanded, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
// C:\code\MyMod\MOD\bin\this!!!!!!!1\1.4\Assemblies\VanillaPsycastsExpanded.dll
// Decompiled with ICSharpCode.Decompiler 7.1.0.6543
#endregion

using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using RI_Talisman;
using RimWorld;
using RimWorld.QuestGen;
using RimWorld.SketchGen;
using UnityEngine;
using Verse;
using Verse.Noise;

namespace WhoXiuXian
{
    public class RI_SketchResolver_CryptosleepCasketRoomt : SketchResolver
    {
        private static List<IntVec3> tmpCells = new List<IntVec3>();

        protected override bool CanResolveInt(ResolveParams parms)
        {
            if (parms.rect.HasValue)
            {
                return parms.sketch != null;
            }

            return false;
        }
        protected override void ResolveInt(ResolveParams parms)
        {

            CellRect rect = parms.rect.Value;
            CellRect cellRect = SketchGenUtility.FindBiggestRect(parms.sketch, (IntVec3 p) => rect.Contains(p) && !parms.sketch.ThingsAt(p).Any());
            if (cellRect == CellRect.Empty)
            {
                return;
            }

            tmpCells.Clear();
            Rot4 dir = ((cellRect.Width > cellRect.Height) ? Rot4.North : Rot4.East);
            tmpCells.AddRange(cellRect.GetEdgeCells(dir));
            tmpCells.AddRange(cellRect.GetEdgeCells(dir.Opposite));
            tmpCells.Clear();

            bool haveCC = false;
            ThingDef thingDef = RI_T_DefOfs.RI_AncientCultivatorCryptosleepCasket;

            var intInRange = RI_RandomUtility.GetCircularRegion(rect.CenterCell, 30);
            foreach (var intVec1 in intInRange)
            {
                if (parms.sketch.ThingsAt(intVec1).Count() > 0)
                {
                    if (parms.sketch.ThingsAt(intVec1).First().def == RI_T_DefOfs.RI_AncientCultivatorCryptosleepCasket)
                    {
                        haveCC = true;
                        break;
                    }
                }
            }
            if (haveCC == false)
            {
                parms.sketch.AddThing(thingDef, rect.CenterCell + new IntVec3(-1, 0, -1), Rot4.North);
            }
            else
            {
                parms.sketch.AddThing(RI_T_DefOfs.RI_Building_AncientCryoCapsuleRuin, rect.CenterCell + new IntVec3(-1, 0, -1), Rot4.North);
            }

            RI_RandomUtility.ReplaceWallAndBreakThem(rect, parms.sketch, RI_T_DefOfs.RI_Building_AncientWall, 30, 0.7f);

        }
    }
}

